package o;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint.FontMetrics;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.Layout;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.Pair;
import java.util.ArrayList;
import java.util.List;
import o.bsy.e;

public class bug extends Drawable {
    private int ʻ;
    private int ʼ;
    private CharSequence ʽ = "";
    private Rect ˊ;
    private int ˊॱ;
    private ColorStateList ˋ;
    private int ˋॱ;
    private Alignment ˎ = Alignment.ALIGN_NORMAL;
    private TextPaint ˏ;
    private boolean ˏॱ = false;
    private float ͺ = 0.0f;
    private Resources ॱ;
    private List<btr> ॱˊ = new ArrayList();
    private int ॱॱ;
    private int ᐝ;

    public bug(Context context) {
        this.ॱ = context.getResources();
        this.ˊ = new Rect();
        this.ˏ = new TextPaint(1);
        this.ˏ.density = this.ॱ.getDisplayMetrics().density;
        this.ˏ.setDither(true);
        this.ˊॱ = context.getResources().getDimensionPixelSize(e.ʽ);
        this.ˏ.setTextSize((float) this.ˊॱ);
        cjz.ˏ(this.ˏ);
        this.ॱॱ = context.getResources().getDimensionPixelSize(e.ʻॱ);
        this.ʻ = context.getResources().getDimensionPixelSize(e.ˋᐝ);
        this.ᐝ = context.getResources().getDimensionPixelSize(e.ˋˋ);
        this.ʼ = context.getResources().getDimensionPixelSize(e.ˋˊ);
    }

    public void ˏ(CharSequence charSequence) {
        if (charSequence == null) {
            charSequence = "";
        }
        this.ʽ = charSequence;
    }

    public CharSequence ˎ() {
        return this.ʽ;
    }

    private boolean ˋ(int[] iArr) {
        int colorForState = this.ˋ.getColorForState(iArr, -16777216);
        if (this.ˏ.getColor() == colorForState) {
            return false;
        }
        this.ˏ.setColor(colorForState);
        return true;
    }

    protected void onBoundsChange(Rect rect) {
        this.ˊ.set(rect);
    }

    public boolean isStateful() {
        return this.ˋ.isStateful();
    }

    protected boolean onStateChange(int[] iArr) {
        return ˋ(iArr);
    }

    public int getIntrinsicHeight() {
        if (this.ˊ.isEmpty()) {
            return -1;
        }
        return this.ˊ.bottom - this.ˊ.top;
    }

    public int getIntrinsicWidth() {
        return (int) this.ͺ;
    }

    public void draw(Canvas canvas) {
        this.ͺ = 0.0f;
        int size = this.ॱˊ.size();
        float f = 0.0f;
        float f2 = 0.0f;
        for (int i = 0; i < size; i++) {
            Pair ॱ = ॱ(canvas, f2, f, (btr) this.ॱˊ.get(i));
            f2 = ((Float) ॱ.first).floatValue();
            f = ((Float) ॱ.second).floatValue();
            if (i < size - 1) {
                this.ͺ += (float) this.ॱॱ;
            }
        }
    }

    public float ॱ() {
        return this.ͺ;
    }

    private Pair<Float, Float> ॱ(Canvas canvas, float f, float f2, btr o_btr) {
        canvas.translate(f, -f2);
        Context ˏ = bqy.ˋ().ˏ();
        ˏ(ˏ.getResources().getText(o_btr.ˎ()));
        if (this.ˏॱ) {
            this.ˏ.setColor(this.ˋॱ);
        } else {
            this.ˏ.setColor(ˏ.getResources().getColor(o_btr.ˊ()));
        }
        this.ˏ.setTextSize((float) this.ˊॱ);
        float ˏ2 = ˏ();
        Drawable drawable = ˏ.getResources().getDrawable(o_btr.ॱ());
        if (this.ˏॱ) {
            drawable = epo.ॱ(drawable, this.ˋॱ);
        }
        float f3 = (((float) this.ॱॱ) + ˏ2) + ((float) this.ॱॱ);
        this.ͺ += f3;
        float dimension = ˏ.getResources().getDimension(e.ˈ);
        drawable.setBounds(0, 0, (int) f3, (int) dimension);
        drawable.draw(canvas);
        FontMetrics fontMetrics = this.ˏ.getFontMetrics();
        float f4 = fontMetrics.descent - fontMetrics.ascent;
        Rect bounds = getBounds();
        float f5 = (dimension - f4) / 2.0f;
        canvas.translate((float) (bounds.left + this.ॱॱ), ((float) bounds.top) + f5);
        new StaticLayout(this.ʽ, this.ˏ, (int) Math.ceil((double) Layout.getDesiredWidth(this.ʽ, this.ˏ)), this.ˎ, 1.0f, 0.0f, false).draw(canvas);
        return new Pair(Float.valueOf(((float) (this.ॱॱ * 2)) + ˏ2), Float.valueOf(f5));
    }

    private float ˏ() {
        ˊ((int) this.ˏ.measureText(ˎ().toString()));
        return this.ˏ.measureText(ˎ().toString());
    }

    public void setAlpha(int i) {
        if (this.ˏ.getAlpha() != i) {
            this.ˏ.setAlpha(i);
        }
    }

    public int getOpacity() {
        return this.ˏ.getAlpha();
    }

    public void setColorFilter(ColorFilter colorFilter) {
        if (this.ˏ.getColorFilter() != colorFilter) {
            this.ˏ.setColorFilter(colorFilter);
        }
    }

    private void ˊ(int i) {
        if (this.ʻ != -1 && this.ʻ < i) {
            i = this.ʻ;
        }
        if (i >= 0 && ((float) this.ᐝ) > 0.0f && ((float) this.ʼ) > 0.0f) {
            float f = (float) this.ˊॱ;
            CharSequence ˎ = ˎ();
            this.ˏ.setTextSize(f);
            double measureText = (double) this.ˏ.measureText(ˎ.toString());
            while (measureText > ((double) i) && f > ((float) this.ᐝ)) {
                f -= (float) this.ʼ;
                this.ˏ.setTextSize(f);
                measureText = (double) this.ˏ.measureText(ˎ.toString());
            }
            if (this.ˏ.measureText(ˎ.toString()) > ((float) this.ʻ)) {
                f = this.ˏ.measureText("...");
                int i2 = 1;
                String charSequence = ˎ.toString();
                do {
                    charSequence = charSequence.substring(0, charSequence.length() - i2);
                    i2++;
                } while (((float) this.ʻ) < this.ˏ.measureText(charSequence) + f);
                ˏ(charSequence + "...");
            }
        }
    }

    public void ॱ(boolean z, int i) {
        this.ˏॱ = z;
        this.ˋॱ = i;
    }

    public void ˋ(List<String> list) {
        this.ॱˊ.clear();
        if (list != null && list.size() != 0) {
            for (String str : list) {
                try {
                    btr ॱ = bto.ॱ(Integer.parseInt(str));
                    if (ॱ != null) {
                        this.ॱˊ.add(ॱ);
                    }
                } catch (Exception e) {
                    bqx.ˋ("StampDrawable", "parseInt error:" + str);
                }
            }
        }
    }

    public void ॱ(int i) {
        this.ॱˊ.clear();
        btr ˊ = bto.ˊ(i);
        if (ˊ != null) {
            this.ॱˊ.add(ˊ);
        }
    }
}
